
const express = require("express");
const route = express.Router();
const adminModel = require("../db/model/adminModel")

const isLoginMiddle = require("../middleware/isLoginMiddle")

//删除管理员接口
route.delete("/deleteAdmin",isLoginMiddle, async (req, res) => {
  //根据请求头拿到到要删除的管理员名字
  const { adminName } = req.query
  // console.log(req.query);
  // console.log(adminName);
  // console.log(req.query);
  // console.log(adminName );

  try {
    //adminModel.deleteOne() 函数返回值是一个 对象 对象身上有一个deletedCount 方法  记录删除了 几个
    const re = await adminModel.deleteOne({ adminName })
    // console.log(re.deletedCount);

    if (!re.deletedCount > 0) {
      return res.send({
        "code": 10001,
        "message": "删除失败",
        "data": null
      })
    }

    res.send({
      "code": 10000,
      "message": "删除成功",
      "data": null
    })

  } catch (e) {
    res.send(
      {
        "code": 10002,
        "message": "删除操作失败" +e.message,
        "data": null
      }
    )
  }

})


module.exports = route;



